package top.ooyyh.controller;

import top.ooyyh.model.User;
import top.ooyyh.util.TerminalUI;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * 应用主控制器
 */
public class AppController {
    private Scanner scanner = new Scanner(System.in);
    private AuthController authController = new AuthController();

    /**
     * 启动应用
     */
    public void start() {
        while (true) {
            TerminalUI.clearScreen();
            TerminalUI.printWelcomeBanner();
            
            List<String> menuItems = new ArrayList<>();
            menuItems.add("登录");
            menuItems.add("注册");
            menuItems.add("邮箱注册（开发中）");
            menuItems.add("退出");
            
            TerminalUI.printMenu("请选择操作", menuItems);
            
            System.out.print(TerminalUI.CYAN + "➜ " + TerminalUI.RESET + "请输入选项 (1-4): ");
            String choice = scanner.nextLine().trim();
            
            User user = null;
            switch (choice) {
                case "1":
                    user = authController.showLogin();
                    break;
                case "2":
                    user = authController.showRegister();
                    break;
                case "3":
                    authController.showEmailRegister();
                    break;
                case "4":
                    TerminalUI.printInfo("感谢使用，再见！");
                    return;
                default:
                    TerminalUI.printError("无效的选项，请重新选择！");
                    TerminalUI.waitForEnter();
            }
            
            // 如果登录成功，进入主界面
            if (user != null) {
                MainController mainController = new MainController(user);
                mainController.showMainMenu();
            }
        }
    }
}

